package threading;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Microsoft
 * Date: 2023-07-07
 * Time: 15:21
 */
public class ThreadDemo10 {
    public static void main(String[] args) {
        Thread t = new Thread(() -> {
            //currentThread 是获取当前线程的示例
            //此处currentThread 获取到的对象就是t
            //isInterrupted就是 t 对象里自带的一个标志位
            while (!Thread.currentThread().isInterrupted()) {
                System.out.println("hello t");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    break;
                }
            }
        });
        t.start();

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        //把t内部的标志位给设置成true
        t.interrupt();
    }
}